#include "rcs.h"
#include <QString>
#include "sysconf.h"

extern BoxInfo boxInfo;


Rcs::Rcs()
{
    init();
}

void Rcs::init()
{
    start="";
    systemStr="";
    network="";
    nfs="";
    ftp="";
    telnet="";

    start.append("#! /bin/sh\n")
            .append("\n");

    systemStr.append("#system\n")
            .append("echo \"running /etc/init.d/rcS\"\n")
            .append("# mount the /proc file system\n")
            .append("/bin/mount -t proc proc /proc\n")
            .append("# echo \"mount tmpfs filesystem to /tmp\"\n")
            .append("/bin/mount -t sysfs sysfs /sys\n")
            .append("/bin/mount -t tmpfs tmpfs /dev\n")
            .append("#echo \"mount ramfs filesystem to /var\"\n")
            .append("/bin/mount -t ramfs none /var\n")
            .append("/bin/rm -fr /media/*\n")
            .append("echo \"starting mdev...\"\n")
            .append("/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug\n")
            .append("/sbin/mdev -s\n")
            .append("/bin/ln -s /dev/rtc0 /dev/rtc\n")
            .append("#/bin/mount -t yaffs2 /dev/mtdblock1 /home/\n")
            .append("/bin/hostname -F /etc/hostname\n")
            .append("#/sbin/hwclock --hctosys\n")
            .append("/sbin/insmod /lib/modules/2.6.24/can.ko\n")
            .append("/sbin/insmod /lib/modules/2.6.24/yjwcan.ko\n")
            .append("#/sbin/insmod /lib/modules/2.6.24/adm706.ko\n")
            .append("#/sbin/insmod /lib/modules/2.6.24/ads8344.ko\n")
            .append("/sbin/insmod /lib/modules/2.6.24/beep_dev.ko\n")
            .append("/sbin/insmod /lib/modules/2.6.24/gpio_dev.ko\n")
            .append("#/sbin/insmod /lib/modules/2.6.24/keypad.ko\n")
            .append("\n");

    network.append("#network\n")
            .append("/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0\n")
            .append("/sbin/ifconfig eth0 hw ether AE:45:67:56:00:01\n")
            .append("/sbin/ifconfig eth0 ").append(boxInfo.ip2).append(" netmask ").append(boxInfo.netmask2).append("\n")
            .append("/sbin/ifconfig eth0 down\n")
            .append("/sbin/ifconfig eth1 ").append(boxInfo.ip1).append(" netmask ").append(boxInfo.netmask1).append("\n")
            .append("/sbin/ifconfig eth1 up\n")
            .append("\n");

    nfs.append("#nfs\n")
            .append("/bin/mount -t nfs -o nolock 10.61.5.174:/home/nfs /mnt/nfs\n")
            .append("\n");

    ftp.append("#ftp\n")
            .append("tcpsvd 0 21 ftpd -w -t 3600 /  &\n")
            .append("\n");

    telnet.append("#telnet\n")
            .append("/bin/mkdir /dev/pts\n")
            .append("mknod -m 666 /dev/ptmx c 5 2\n")
            .append("/bin/mount -t devpts devpts /dev/pts\n")
            .append("/usr/sbin/telnetd &\n")
            .append("\n");
}


QString Rcs::stdRcs()
{
    init();
    QString ret="";
    ret.append(start).append(systemStr).append(network).append(nfs).append(ftp);
    if(boxInfo.isTelnet)
    {
        ret.append(telnet);
    }
    return ret;
}
